<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //转化为驼峰命名法
        var s1 = "get-element-by-id"
        // 转化为 getElementById
        function upDatabase(x){
            let reg = /-\w/g
            console.log(x.match(reg))
            // console.log(x.replace(reg))
            return x.replace(reg,function(d){
                console.log(d)
                return d.slice(1).toUpperCase()
            })
        }
        function upDataBase2(x){
            let arr = x.split('-')
            let str =''
            arr.forEach(element => {
                str = str+element.charAt(0).toUpperCase() + element.slice(1)
            });
            return str
        }
        console.log(upDatabase(s1))
        console.log(upDataBase2(s1))
        
        //upDatabase(s1)
        //实现千位分割
        //保留三位小数
        // parseToMoney(1234.56); // return '1,234.56'
        // parseToMoney(123456789); // return '123,456,789'
        // parseToMoney(1087654.321); // return '1,087,654.321'
        function parseToMoney(num){
            num = parseFloat(num.toFixed(3))
            console.log(num)
            let [integer,decimal] = String.prototype.split.call(num,'.')
            console.log(integer)
            console.log(decimal)
            integer = integer.replace(/\d(?=(\d{3})+$)/g,'$&,')
            return integer+(decimal?'.'+decimal:'')
        }
        // function parseToMoney(str){
        //     // 仅仅对位置进⾏匹配
        //     let re = /(?=(?!\b)(\d{3})+$)/g;
        //     return str.replace(re,',');
        //     }
        console.log(parseToMoney(1234.56)); // return '1,234.56'
        console.log(parseToMoney(123456789)); // return '123,456,789'
        console.log(parseToMoney(1087654.321)); // return '1,087,654.321'

    </script>
</body>
</html>